var vm = new Vue({
	el: '#app',
	data: {
		items: [],
		loaded: false
	},
	mounted: function() {
		getMailList();
		//getCoinQbbList();
	}
});
/**
 * 扫描二维码并且解析
 */
var qb = localStorage.getItem("qb");
$("#qb").val(qb);
window.onbeforeunload = function(e) {
	localStorage.removeItem('qb');
}

function startCan() {
	setTimeout('window.location.href = "qr4.html"', 100);
}
var aid;

function getMailList() {
	var txl = localStorage.getItem("txl");
	var obj = JSON.parse(txl);
	aid = obj.aId;
	$("#userName").val(obj.friend_name);
	$("#qb").val(obj.friend_addr);
	$("#title").text(obj.title);
	$("#names").text(obj.name);
}
var first = true;

function updateMailList() {
	//$(".weui-btn").attr("disabled", false);
	var options = $("#line option:selected").val();
	var updateMailListReqbody = {
		"type": 0,
		"aId": aid,
		"coinId": options,
		"name": $("#userName").val().trim(),
		"address": $("#qb").val().trim()
	};
	if(first) {
		first = false;
		$.ajax({
			type: "POST",
			url: ip + "platform/user/updateAddressBook.m",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: updateMailListReqbody,
			success: function(data) {
				if(data.statusCode == 0) {
					//$(".weui-btn").attr("disabled", true);
					$.toptip("修改联系人成功！", 'success');
					setTimeout('window.location.href = "mailList.html"', 100);
				} else if(data.statusCode == 1000) {
					$.toptip("登录失效！", 'error');
					setTimeout('window.location.href = "signIn.html"', 100);
				} else {
					$.toptip(data.resultDesc, 'error');
				}
			}
		});
	}
}

function getCoinQbbList() {
	$.ajax({
		type: "GET",
		url: ip + "platform/trade/getCoinQbbList.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				var html = '';
				for(var i = 0; i < (data.result).length; i++) {
					html += '<option value="' +
						data.result[i].id + '">' +
						data.result[i].name +
						'</option>';
				}
				$("#line").append(html);
			} else if(data.statusCode == 1000) {
				$.toptip("登录失效！", 'error');
				setTimeout('window.location.href = "signIn.html"', 1000);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}